package com.csu.petstore.controller;

import com.csu.petstore.common.CommonResponse;
import com.csu.petstore.pojo.Account;
import com.csu.petstore.pojo.Cart;
import com.csu.petstore.pojo.Order;
import com.csu.petstore.service.OrderService;
import com.csu.petstore.service.UserService;
import com.csu.petstore.vo.OrderVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Validated
public class OrderController {
    @Autowired
    private OrderService orderService;

//    @GetMapping("neworderform")
//    public CommonResponse<String> OpenNeworderform(@Validated Order order, HttpServletRequest request) {
//        HttpSession session = request.getSession();
//        Account account = (Account) session.getAttribute("account");
//        Cart cart = (Cart) session.getAttribute("cart");
//
//        if (account == null) {
//            session.setAttribute("message", "You must sign on before attempting to check out.  Please sign on and try checking out again.");
//            return "account/signon";
//        } else if (cart != null) {
//            order.initOrder(account, cart);
//            session.setAttribute("order", order);
//
//        }
//        return "order/neworderform";
//    }
//    @PostMapping("confirmorder")
//    public String OpenConfirmorder(
//            @RequestParam("newOrder") String newOrder, HttpServletRequest request
//    ) {
//        HttpSession session = request.getSession();
//
//        return ("order/confirmorder");
//    }
//    @GetMapping("neworder")
//    public String OpenNewmorder(HttpServletRequest request){
//        HttpSession session = request.getSession();
//        Order order = (Order) session.getAttribute("order");
//        System.out.println(order);
//        Cart cart = (Cart ) session.getAttribute("cart");
//        orderService.insertOrder(order,cart);
//        System.out.println("1");
//        return ("order/neworder");
//    }
    @GetMapping("/orders/{orderId}")
    public CommonResponse<Order> GetOrderByOrderID(@PathVariable("orderId") String orderId){
        return orderService.getOrder(orderId);
    }
    @PostMapping("/orders")
    public CommonResponse<String> AddOrder(@RequestBody OrderVO orderVO){

        return orderService.insertOrder(orderVO);
    }
}
